package com.example.prom.ok.y2022.controller.twilio;

import com.twilio.Twilio;
import com.twilio.base.Page;
import com.twilio.rest.verify.v2.VerificationAttempt;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.List;

public class TwilioMsgController {
    public static void main(String[] args) {
        // okx
        Twilio.init("ACbb9cb74f6ff931166050041d1a1736cc", "571de3566ad4eb63f48ef22ad34750ff");
        // okcoin
//        Twilio.init("AC4825f78cb8564d671d4eeb25a990c747", "3bdb0326fc377389d63db3f0b8a2fbeb");
        // oklink
//        Twilio.init("AC15b97c82d35b37c6aeed74f72e109471", "3aa5951acdec9796760686c320821a87");
        ZoneId zoneId = ZoneId.of("Asia/Shanghai");
        ZonedDateTime now = ZonedDateTime.now(zoneId);
        LocalDateTime localDateTime = LocalDateTime.of(now.getYear(), now.getMonthValue(), now.getDayOfMonth(), 0, 0, 0);
        ZonedDateTime zonedDateTime = ZonedDateTime.of(localDateTime, zoneId);
        ZonedDateTime dateCreateAfter = zonedDateTime.minusDays(1);

        System.out.println(dateCreateAfter.toLocalDateTime());

//        ResourceSet<VerificationAttempt> verificationAttempts =
//                VerificationAttempt
//                        .reader()
//                        .setDateCreatedBefore(zonedDateTime)
//                        .setDateCreatedAfter(dateCreateAfter)
//                        .limit(10)
//                        .read();
//
//        System.out.println(verificationAttempts.getLimit());
//        System.out.println(verificationAttempts.getPageSize());
//        System.out.println(verificationAttempts.getPageLimit());
//        int i = 1;
//        for(VerificationAttempt record : verificationAttempts) {
//            Map<String, Object> channelData = record.getChannelData();
////            System.out.println(JSON.toJSONString(channelData));
////            System.out.println(record.getDateCreated());
//            System.out.println(JSON.toJSONString(record));
//            System.out.println(i++);
//        }

        Page<VerificationAttempt> verificationAttemptPage = VerificationAttempt
                .reader()
                .setDateCreatedBefore(zonedDateTime)
                .setDateCreatedAfter(dateCreateAfter)
                .firstPage();

        verificationAttemptPage.getNextPageUrl("");
        System.out.println(verificationAttemptPage.getPageSize());
        System.out.println(verificationAttemptPage.getRecords());
        System.out.println(verificationAttemptPage.hasNextPage());
        List<VerificationAttempt> records = verificationAttemptPage.getRecords();
        System.out.println(records.get(0).getSid()); //VL11970eb42172b1f42c10e1944acbd38a
    }
}
